<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "teacher".
 *
 * @property int $ID ID
 * @property int $XXID 学校ID
 * @property int|null $BMID 部门院系ID
 * @property int|null $ZYID 专业ID
 * @property int $GRID 个人ID
 * @property string $GH 工号
 * @property string $GWMC 岗位名称
 * @property string $ZW 职务
 * @property string $ZC 职称
 * @property string $RZSJ 任职时间
 * @property string|null $LRSJ 离任时间
 * @property string|null $BZ 备注
 * @property string $ZT 状态
 *
 * @property CourseTeacher[] $courseTeachers
 * @property School $xX
 * @property Department $bM
 * @property Person $gR
 * @property Major $zY
 */
class Teacher extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'teacher';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['XXID', 'GH', 'GWMC', 'ZW', 'ZC', 'RZSJ', 'ZT'], 'required'],
            [['XXID', 'BMID', 'ZYID', 'GRID'], 'integer'],
            [['RZSJ', 'LRSJ'], 'safe'],
            [['GH', 'ZW', 'ZC'], 'string', 'max' => 20],
            [['GWMC'], 'string', 'max' => 50],
            [['BZ'], 'string', 'max' => 500],
            [['ZT'], 'string', 'max' => 10],
            [['XXID'], 'exist', 'skipOnError' => true, 'targetClass' => School::className(), 'targetAttribute' => ['XXID' => 'ID']],
            [['BMID'], 'exist', 'skipOnError' => true, 'targetClass' => Department::className(), 'targetAttribute' => ['BMID' => 'ID']],
            [['GRID'], 'exist', 'skipOnError' => true, 'targetClass' => Person::className(), 'targetAttribute' => ['GRID' => 'id']],
            [['ZYID'], 'exist', 'skipOnError' => true, 'targetClass' => Major::className(), 'targetAttribute' => ['ZYID' => 'ID']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'ID' => 'ID',
            'XXID' => '学校ID',
            'BMID' => '部门院系ID',
            'ZYID' => '专业ID',
            'GRID' => '个人ID',
            'GH' => '工号',
            'GWMC' => '岗位名称',
            'ZW' => '职务',
            'ZC' => '职称',
            'RZSJ' => '任职时间',
            'LRSJ' => '离任时间',
            'BZ' => '备注',
            'ZT' => '状态',
        ];
    }

    /**
     * Gets query for [[CourseTeachers]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getCourseTeachers()
    {
        return $this->hasMany(CourseTeacher::className(), ['JSID' => 'ID'])->inverseOf('jS');
    }

    /**
     * Gets query for [[XX]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getXX()
    {
        return $this->hasOne(School::className(), ['ID' => 'XXID'])->inverseOf('teachers');
    }

    /**
     * Gets query for [[BM]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getBM()
    {
        return $this->hasOne(Department::className(), ['ID' => 'BMID'])->inverseOf('teachers');
    }

    /**
     * Gets query for [[GR]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getGR()
    {
        return $this->hasOne(Person::className(), ['ID' => 'GRID'])->inverseOf('teachers');
    }

    /**
     * Gets query for [[ZY]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getZY()
    {
        return $this->hasOne(Major::className(), ['ID' => 'ZYID'])->inverseOf('teachers');
    }
}
